home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / DRVALID.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  76 lines

  1. .I 85 74
  2.  
  3. /*
  4. **  drvrdy()
  5. **
  6. **  Checks whether a drive with removable media is ready.
  7. **
  8. **  Arguments: 1 - target drive (0 = A;, 1 = B:, etc.)
  9. **
  10. **  Returns:   TRUE  - drive is ready
  11. **             FALSE - drive is not ready
  12. **             ERROR - other read error
  13. **
  14. **  Side effects: none
  15. */
  16.  
  17. LOGICAL drvrdy(int drive)
  18. {
  19.       int status;
  20.       char buf[2048];         /* nice & roomy   */
  21.  
  22.       status = AbsDiskRead(drive, 1, 0, buf);
  23.       printf("AbsDiskRead(%d, 1, 0) returned 0x%X\n", drive, status);
  24.       if (0 == status)
  25.             return TRUE;
  26.       status &= 0xff;
  27.       if (2 == status)
  28.             return FALSE;
  29.       else  return ERROR;
  30. }
  31.  
  32. #ifdef TEST
  33.  
  34. #include <stdio.h>
  35. #include <ctype.h>
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39.       int drive;
  40.  
  41.       if (2 > argc)
  42.       {
  43.             puts("Usage: DRVALID drive[:]");
  44.             return EXIT_FAILURE;
  45.       }
  46.       drive = toupper(*argv[1]);
  47.       if (!isalpha(drive))
  48.       {
  49.             puts("Error: Invalid drive name");
  50.             return EXIT_FAILURE;
  51.       }
  52.       printf("Drive %c: is %svalid\n", drive,
  53.             drvalid(drive - 'A') ? "" : "not ");
  54.       if (2 < _osmajor)
  55.       {
  56.             union REGS regs;
  57.  
  58.             regs.x.ax = 0x4408;
  59.             regs.h.bl = (unsigned char)(drive - '@');
  60.             intdos(®s, ®s);
  61.             printf("ioctl returned Cflag=%s\n",
  62.                   regs.x.cflag ? "TRUE" : "FALSE");
  63.             printf("ioctl returned AX=0x%X\n", regs.x.ax);
  64.             printf("Drive %c is%s removable\n", drive,
  65.                   regs.x.ax ? " not" : "");
  66.             if (0 == regs.x.ax)
  67.             {
  68.                   printf("Drive %c is %sready\n", drive,
  69.                         drvrdy(drive - 'A') ? "" : "not ");
  70.             }
  71.       }
  72.       return EXIT_SUCCESS;
  73. }
  74.  
  75. #endif /* TEST */
  76.